﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Yeap.Config;
using Yeap.Kernel.Storage;

namespace Yeap.Kernel.Utils
{
    public static class SiteSettingPool
    {
        public static Int32 MinimalCourse
        {
            get
            {
                var siteSettingsRepository = new SiteRepository();
                Int32 targetValue;
                try
                {
                    targetValue = Convert.ToInt32(siteSettingsRepository.GetSetting(Constants.SiteSettingKeys.MinimalCourse));
                }
                catch (FormatException)
                {
                    throw new Exception(Constants.ExceptionMessages.InvalidSiteSettingIntValue);
                }
                catch (OverflowException)
                {
                    throw new Exception(Constants.ExceptionMessages.SiteSettingOverflow);
                }
                return targetValue;
            }
        }

        public static Int32 MaximalCourse
        {
            get
            {
                var siteSettingsRepository = new SiteRepository();
                Int32 targetValue;
                try
                {
                    targetValue = Convert.ToInt32(siteSettingsRepository.GetSetting(Constants.SiteSettingKeys.MaximalCourse));
                }
                catch (FormatException)
                {
                    throw new Exception(Constants.ExceptionMessages.InvalidSiteSettingIntValue);
                }
                catch (OverflowException)
                {
                    throw new Exception(Constants.ExceptionMessages.SiteSettingOverflow);
                }
                return targetValue;
            }
        }

        public static Int32 CurrentYear
        {
            get
            {
                var siteSettingsRepository = new SiteRepository();
                Int32 targetValue;
                try
                {
                    targetValue = Convert.ToInt32(siteSettingsRepository.GetSetting(Constants.SiteSettingKeys.CurrentYear));
                }
                catch (FormatException)
                {
                    throw new Exception(Constants.ExceptionMessages.InvalidSiteSettingIntValue);
                }
                catch (OverflowException)
                {
                    throw new Exception(Constants.ExceptionMessages.SiteSettingOverflow);
                }
                return targetValue;
            }
        }

        public static Int32 InitialYear
        {
            get 
            { 
                var siteSettingsRepository = new SiteRepository();
                Int32 targetValue;
                try
                {
                    targetValue = Convert.ToInt32(siteSettingsRepository.GetSetting(Constants.SiteSettingKeys.InitialYear));
                }
                catch (FormatException)
                {
                    throw new Exception(Constants.ExceptionMessages.InvalidSiteSettingIntValue);
                }
                catch (OverflowException)
                {
                    throw new Exception(Constants.ExceptionMessages.SiteSettingOverflow);
                }
                return targetValue;
            }
        }
    }
}